<?php
/** 
 * EGP Framework
 *
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */

!defined('EGP_LIB_DIR') && die('Access Deny!');

/**
 * 财付通支付响应处理
 *
 * @package    classes
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */
class EGP_Payment_Respond_Tenpay_Mediate extends EGP_Payment_Respond_Abstract
{

    /**
     * 分析返回的结果
     *
     * @param  array  $params
     * @return array
     */
    public function parse(array $params)
    {
        if (isset($params['total_fee'])) {
            $params['total_fee'] = number_format($params['total_fee'] / 100, 2);
        }
        if (isset($params['trade_price'])) {
            $params['trade_price'] = number_format($params['trade_price'] / 100, 2);
        }
        if (isset($params['transport_fee'])) {
            $params['transport_fee'] = number_format($params['transport_fee'] / 100, 2);
        }

        return parent::parse($params);
    }

    /**
     * 获取订单号
     *
     * @return string
     */
    public function getId()
    {
        return $this->_result['mch_vno'];
    }

    /**
     * 获取订单总金额
     *
     * @return float
     */
    public function getAmount()
    {
        return $this->_result['total_fee'];
    }

    /**
     * 获取付款时间
     *
     * @return integer
     */
    public function getTime()
    {
        return time();
    }

    /**
     * 获取支付状态
     *
     * @return integer
     */
    public function getStatus()
    {
        if ($this->_result['retcode'] == 0) {
            switch ($this->_result['status']) {
                case 1: //初始化
                    return EGP_Payment::STAT_INITED;
                case 2: //等待付款
                    return EGP_Payment::STAT_WAIT_PAY;
                case 3: //已收款，等待发货
                    return EGP_Payment::STAT_PAID;
                case 4: //已发货
                    return EGP_Payment::STAT_SHIPPED;
                case 5: //已收货
                    return EGP_Payment::STAT_SUCCEED;
                case 6: //超时
                    return EGP_Payment::STAT_FAILED;
                case 7: //修改交易价格成功
                case 8: //买家退款
                case 9: //退款成功
                case 10: //退款关闭
                    return ; //@TODO
            }
        }
        return EGP_Payment::STAT_FAILED;
    }


}